<?php
namespace Admin\Controller;
use Common\Controller\AdminbaseController;
class SysconfigController extends AdminbaseController
{
	// 系统配置首页
	public function index()
	{
        //筛选条件
		$config_title = I('request.config_title');
        $config_remark = I('request.config_remark');

        if($config_title){
            $where['config_title'] = array('like',"%$config_title%");
        }
        if($config_remark){
            $where['config_remark'] = array('like',"%$config_remark%");
        }
		$where['config_type'] = '1';

		$count = M('sys_config')->where($where)->count();
		$page = $this->page($count, 10);
		$configdata = M('sys_config')
					->where($where)
					->order('id')
					->limit($page->firstRow, $page->listRows)
					->select();
		$this->assign("page", $page->show('Admin'));
		$this->assign('configdata',$configdata);
		$this->display();
	}

	// 系统配置修改页面
	public function configedit()
	{
		$config=D('sys_config')->where(array("id"=>I('get.id')))->find();
		$this->assign('config',$config);
		$this->display();
	}

	// 配置修改提交
	public function edit_post()
	{
		if(IS_POST){
			if (!empty($_POST)) {
				$id = I('post.id');
				$date['config_value'] = I('post.config_value');
                /*当前管理员name*/
                $date['update_user'] = get_current_admin_name();
                $date['update_time'] = get_admin_time();
			 	$code = M('sys_config')->where(array('id'=>$id))->save($date);
			 	if ($code >= 1) {
				   	$this->success("修改成功！", U("Sysconfig/index"));
			 	}else{
				   	$this->error("修改失败！");
			 	}
			}
		}
	}
}
